package com.hna.eking.AirGisPlt.Rest;

import java.util.List;

import org.mybatis.spring.MyBatisSystemException;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.hna.eking.AirGisPlt.MybatisImp.AirportInfo;

import com.hna.eking.AirGisPlt.Mapper.AirportInfoMapper;

@RestController
@MapperScan({"com.hna.eking.AirGisPlt.Mapper", "com.hna.eking.AirGisPlt.MybatisImp"})
public class AirportInfoRest {
	@Autowired
	AirportInfo AirInfoImp;
	List<AirportInfoMapper> AirInfoRet;
	private static final Logger logger = LoggerFactory.getLogger(AirportInfoRest.class);

	@RequestMapping(value = "/AirportPos", method = RequestMethod.GET)
	@ResponseBody
	public String GetAirportPos(@RequestParam(value = "AirportName") String AirportName) {
		JSONObject json = new JSONObject();
		if (AirportName == null || "".equals(AirportName)) {
			json.put("ErrorCode", "401");
			return json.toJSONString();
		}
		try {
			AirInfoRet = AirInfoImp.getByAirportName("%" + AirportName + "%");
			json.put("ErrorCode", "200");
			json.put("PosX", AirInfoRet.get(0).PosX);
			json.put("PosY", AirInfoRet.get(0).PosY);
			json.put("AID", AirInfoRet.get(0).AID);
			json.put("AirportName", AirInfoRet.get(0).aname);
			logger.info("result" + json.toJSONString());
			return json.toJSONString();
		} catch (MyBatisSystemException e) {
			json.put("ErrorCode", "402");
			e.printStackTrace();
		}
		return "405";
	}
}
